<?php
class Menu
{
	public function listarPagina(){
		$db = Zend_Registry::get('db');
		$sql = "SELECT grm.ds_nome as grupo, men.ds_nome as menu, men.ds_link link, nm_icone as icone
			  FROM menu grm
			  JOIN pagina men
  			    ON grm.id_menu = men.id_menu
 			 WHERE grm.in_ativo = 1
  			   AND men.in_ativo = 1
 			 ORDER BY grm.nr_ordem, men.nr_ordem ";
		echo $sql;
		return $db->query($sql);
	}

	public function buscarPagina($id_grupo_acesso){
		$db = Zend_Registry::get('db');
		$sql = "select pag.ds_nome menu, men.ds_nome grupo, pag.ds_link link, nm_icone as icone
				  from pagina pag,
				       menu men,
				       grupo_pagina grp
				 where pag.id_menu=men.id_menu
				   and pag.id_pagina=grp.id_pagina
   				   and pag.in_ativo = 1
   				   and men.in_ativo = 1
   				   and grp.id_grupo_acesso = {$id_grupo_acesso}
				 ORDER BY men.nr_ordem, pag.nr_ordem ";
		return $db->query($sql);
	}

	public function contGrupoPagina(){
		$db = Zend_Registry::get('db');
		$sql = "select count(men.id_menu) as cont
	  				   from menu men,
				       pagina pag
				 where men.id_menu = pag.id_menu
				   and men.in_ativo = 1
				   and men.in_ativo = 1";
		$result = $db->query($sql)->fetch();
		return $result['cont'];
	}
}
